package com.winner.es.exception;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private int code;

    private String message;

    private T data;

    public Result() {
        this.code = EsResultEnum.SUCCESS.getCode();
        this.message = EsResultEnum.SUCCESS.getMessage();
    }

    private Result(T data) {
        this.code = EsResultEnum.SUCCESS.getCode();
        this.message = EsResultEnum.SUCCESS.getMessage();
        this.data = data;
    }

    private Result(EsResultEnum exceptionEnum) {
        this.code = exceptionEnum.getCode();
        this.message = exceptionEnum.getMessage();
    }

    public static Result success() {
        return new Result();
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(data);
    }

    // 在异常全局捕获里写比较简洁
    public static <T> Result<T> error(EsResultEnum exceptionEnum) {
        return new Result<>(exceptionEnum);
    }

}